public class LargestSum {

	public static void main(String[] args) {
		System.out.println(largestConsSum(new int[] { -8, 2, 3, -2, 4, -10 }));
		System.out.println(largestSum(new int[] { -8, 2, 3, -2, 4, -10 }));
	}

	public static int largestConsSum(int[] arr) {
		if (arr == null || arr.length == 0)
			return 0;

		int maxSum = arr[0];
		int curSum = arr[0];

		for (int i = 1; i < arr.length; ++i) {
			curSum = Math.max(curSum+ arr[i], arr[i]); 
			maxSum = Math.max(curSum, maxSum);
		}

		return maxSum;
	}
	
	public static int largestSum(int [] arr){
		if (arr == null || arr.length == 0)
			return 0;
		
		int lsum = arr[0];
		int csum = arr[0];

		for (int i=1; i < arr.length; ++i){
			csum += arr[i];
			if (csum > lsum)
				lsum = csum;
			if (csum < 0)
				csum = Math.max(csum, arr[i]);
		}

		return lsum;
	}
}
